package com.bank.controller;

import com.bank.Utils.StrUtils;
import com.bank.common.JsonResult;
import com.bank.entity.User;
import com.bank.service.UserService;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import javax.validation.constraints.Size;

/**
 * @ProjectName: bankSystem
 * @Author: Jsx
 * @Time: 2020/9/16 8:17
 * @Description:
 */
@Controller
@Validated//如果要在方法参数上使用验证注解,一定要先在这个类上写@Validated这样的注解
public class LoginController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login.do")
    @ResponseBody
    public JsonResult login(@NotEmpty(message = "{name.empty}") String bankCode, @Size(min=1,max = 10) String password, HttpSession session){
        User user = userService.login(bankCode, password);
        session.setAttribute(StrUtils.LOGIN_USER,user);
        JsonResult jsonResult = new JsonResult(1,null);
        return jsonResult;
    }



}
